package com.testingedu.action.front;

import com.testingedu.action.background.RequestContext;
import com.testingedu.jdbcDao.TUserDao;
import com.testingedu.model.TUser;

public class TUserAction extends RequestContext{

	private static final long serialVersionUID = -4754232797189211857L;
	private TUser tUser;
	private static TUserDao tUserDao = new TUserDao(); 
	public void login_() throws Exception {
		String msg = null;
		tUser = tUserDao.login(tUser);
		if(tUser == null) {
			msg = "{\"id\":0,\"msg\":\"用户名或密码错误\"}";
			response.getWriter().write(msg);
			response.getWriter().close();
		} else {
			TUser sessionTUser = new TUser();
			sessionTUser.setAccount(tUser.getAccount());
			sessionTUser.setId(tUser.getId());
			request.getSession().setAttribute("testingedu_user", sessionTUser);
			msg = "{\"id\":1,\"msg\":\"null\"}";
			response.getWriter().write(msg);
			response.getWriter().close();
		}
	}
	public void settUser(TUser tUser) {
		this.tUser = tUser;
	}
	
	/**
	 * 判断用户是否登陆
	 * @throws Exception
	 */
	public void isLogin_() throws Exception{
		String msg = null;
		if(request.getSession().getAttribute("testingedu_user") == null) {
			msg = "{\"login\":\"no\"}";
		} else {
			msg = "{\"login\":\"yes\"}";
		}
		response.getWriter().write(msg);
		response.getWriter().close();
	}
}



